/*
 * @Author: 吴世扬 18368095041@163.com
 * @Date: 2022-09-06 18:23:58
 * @LastEditors: 吴世扬 18368095041@163.com
 * @LastEditTime: 2022-10-12 16:23:46
 * @FilePath: /vuecli508-datav/src/utils/auth.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

import Cookie from 'js-cookie';

const TokenKey = 'token';

export function getToken() {
    return Cookie.get(TokenKey);
}

export function setToken(token: string) {
    return Cookie.set(TokenKey, token);
}

export function removeToken() {
    return Cookie.remove(TokenKey);
}

export const setUserInfo = (userInfo: Record<string, unknown>) => {
    window.localStorage.setItem('userInfo', JSON.stringify(userInfo));
};

export const removeUserInfo = () => {
    window.localStorage.removeItem('userInfo');
};

export const getUserInfo = () => {
    const res = window.localStorage.getItem('userInfo');
    return (res && JSON.parse(res)) || null;
};
